<template>
	<view>
		<navigator url="/pages/address/list?source=1" class="address">
			<view class="address-head">订单配送至</view>
			<view v-if="addressData.phone" class="address-main">
				<image src="../../static/order/address.png" class="address-left"></image>
				<view class="address-text">{{ addressData.province }} {{ addressData.city }} {{ addressData.county }} {{ addressData.address }}</view>
				<image src="../../static/order/right.png" class="address-right"></image>
			</view>
			<view class="padding-tb-sm" v-else>请选择配送地址</view>
			<!-- <view class="address-distance">距离您732米</view> -->
		</navigator>
		<image class="a-bg" src=""></image>
		<view class="goods">
			<view class="goods-head flex">
				<view class="goods-head-text">送达时间</view>
				<view @click="selectTime" style="text-align: right;" class="goods-head-time text-cut padding-right-sm">{{ orderReqeust.predictTime }}</view>
				<image src="../../static/order/time-right.png" class="goods-head-right"></image>
			</view>
			<view class="goods-one" v-if="orderReqeust.skuList.length == 1">
				<image class="goods-img" :src="orderReqeust.skuList[0].skuImg ? orderReqeust.skuList[0].skuImg : orderReqeust.skuList[0].spuImg"></image>
				<view class="goods-text">
					<view class="goods-name">{{ orderReqeust.skuList[0].skuTitle }}</view>
					<view class="goods-tag">
						<view class="goods-price">￥{{ orderReqeust.skuList[0].price / 100 }}</view>
						<view class="goods-yprice">￥{{ orderReqeust.skuList[0].originalPrice / 100 }}</view>
						<view class="goods-number">×{{ orderReqeust.skuList[0].num }}</view>
					</view>
				</view>
			</view>
			<view class="goods-one" v-else>
				<view class="scroll_box">
					<scroll-view scroll-x="true">
						<block v-for="(item, index) in orderReqeust.skuList" :key="index">
							<image class="goods-more-img" :src="item.skuImg ? item.skuImg : item.spuImg"></image>
						</block>
					</scroll-view>
				</view>
				<view class="goods-more-number">共{{ orderReqeust.totalNumber }}件</view>
				<image src="../../static/order/time-right.png" class="goods-more-right"></image>
			</view>
		</view>
		<view class="distribution">
			<view class="distribution-list distribution-list-bottom">
				<view class="distribution-text">配送费</view>
				<view class="distribution-price">{{firstList?'0.00':dandu()>=16?'0.00':'5.00'}}元</view>
			</view>
			<view class="distribution-list distribution-list-bottom" @click="GoYouhui()">
				<view class="distribution-text">优惠卷</view>
				<view class="distribution-price" style="color: red;">{{ youhui }}</view>
			</view>
			<view class="distribution-list">
				<view class="distribution-text">备注</view>
				<view class="distribution-price"><input type="text" v-model="orderReqeust.mono" placeholder="请输入备注信息" /></view>
			</view>
		</view>
		<view class="distribution">
		</view>
		<!-- 底部 -->
		<view class="footer"  @click="submit">
			购买 {{firstList?dandu():dandu()>=16?dandu():parseFloat(dandu() + 5).toFixed(2) }}
			<!-- <view class="submitTwo" @click="submit">
				<view class="">
					<view class="">
						<text>￥</text>
						{{firstList?dandu():dandu()>=16?dandu():parseFloat(dandu() + 5).toFixed(2) }}
						<text>起</text>
					</view>
					<view class="">单独购买</view>
				</view>
			</view> -->
			<!-- <view class="submit" @click="Pinsubmit">
				<view class="">
					<view class="">
						<text>折后￥</text>
						{{ firstList?youhuizhe():dandu()>=16?youhuizhe():parseFloat(youhuizhe() + 5).toFixed(2) }}
						<text>起</text>
					</view>
					<view class="">发起邀请</view>
				</view>
			</view> -->
		</view>
		<uni-popup ref="popup" type="bottom" :animation="true" style="z-index: 9999;">
			<view class="flex align-center justify-between" style="padding: 34rpx 30rpx;background-color: #F2F2F2;">
				<view style="font-size: 32rpx;line-height: 38rpx;color: #1B1C33;">选择送达时间</view>
				<view @click="checkTime" style="font-size: 32rpx;line-height: 38rpx;color: #2AAB34;">确定</view>
			</view>
			<view class="flex justify-between">
				<view style="width: 347rpx;height: 500rpx;background-color: #F2F2F2;">
					<view v-for="(date, index) in dayList" :key="index" @click="chooseDay(index)" :class="[index == dayIndex ? 'bg-white' : '']"
					 style="padding: 25rpx 84rpx 25rpx 59rpx;font-size: 32rpx;line-height: 38rpx;color: #1B1C33;">
						{{ date }}
					</view>
				</view>
				<view class="bg-white" style="width: 404rpx;height: 500rpx;padding-left: 52rpx;position: relative;">
					<scroll-view scroll-y="true" style="width: 404rpx;height: 500rpx;">
						<view v-for="(time, index) in timeList[dayIndex]" :key="index" @click="chooseTime(index)" :class="[index == timeIndex ? 'text-green' : '']"
						 class="solid-bottom" style="padding: 25rpx 0;font-size: 32rpx;line-height: 38rpx;">
							<text v-if="index == 0 && dayIndex == 0 && dayList.length >= 3">{{ time }}</text>
							<text v-else>{{ time[0] + '-' + time[1] }}</text>
						</view>
					</scroll-view>
					<view style="position: absolute;bottom: 0;width: 404rpx;height: 53rpx;background-color: rgba(255,255,255,0.8);"></view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	export default {
		data() {
			return {
				firstList: false,
				huiItem: '',
				youhui: '有可用优惠卷，点击选择',
				shifouchaochu: true,
				year: '',
				orderReqeust: {
					skuList: [],
					totalOriginalPrice: 0,
					totalPrice: 0, //商品折扣（仅算VIP和限时打折）后总价
					totalNumber: 0, //商品件数
					coupon: undefined,
					mono: '',
					takeWay: '',
					freightPrice: 0,
					addressId: undefined,
					predictTime: ''
				},
				skuCategoryPriceMap: {},
				maskState: 0, //优惠券面板显示状态
				couponList: [],
				isVip: false,
				addressData: {
					consignee: '',
					phone: '',
					province: '',
					city: '',
					county: '',
					address: '',
					defaultAddress: false
				},
				submiting: false,
				dayList: [], //配送时间
				dayIndex: 0, //选中配送时间
				timeList: [],
				timeIndex: 0,
				now: 0, //当前小时
				nowTime: 0, //当前分钟
				dateObj: {
					today: 0,
					tomorrow: 1,
					afterTomo: 2
				},
				couponId: '',
				// 每个人的折扣
				eachDiscount: '',
				// 最大用户数
				maxUserCount: '',
				mey: ''
			};
		},
		components: {
			uniPopup
		},
		onShow() {
			// 判断是否选择优惠卷
			if (uni.getStorageSync('youhui') != '') {
				this.youhui = '已选一张';
				this.huiItem = uni.getStorageSync('youhui');
				console.log(this.huiItem, 66668888);
			} else {
				this.youhui = '有可用优惠卷，点击选择';
			}
			// 显示拼团折扣
			this.showZhe();
			var date = new Date();

			this.year = date.getFullYear() + '-';
			console.log(this.year);
			this.checkTime();
			this.isVip = this.$api.isVip();

			console.log('0');
		},
		onLoad(option) {
			//商品数据
			this.firstList = this.$store.state.userInfo.orderNum === 0
			console.log('jie', option);
			if (option.couponId) {
				this.couponId = option.couponId;
			}
			this.isVip = this.$api.isVip();
			const that = this;
			if (option.takeway) {
				that.orderReqeust.takeWay = option.takeway;
			}
			that.orderReqeust.skuList = that.$api.globalData.skuList;
			let totalOriginalPrice = 0;
			let totalPrice = 0;
			let totalNumber = 0;
			let skuCategoryPriceMap = {};
			that.orderReqeust.skuList.forEach(item => {
				console.log(item);
				totalOriginalPrice += item.originalPrice * item.num;
				totalNumber += item.num;
				totalPrice += item.price * item.num;
				// console.log(item.groupShopId,8910);
				// item.skuList=item.groupShopId
				//带用户等级
				//totalPrice += that.isVip ? (item.vipPrice * item.num) : (item.price * item.num)
				//构建category价格Map
				item.categoryIdList.forEach(catItem => {
					if (skuCategoryPriceMap[catItem]) {
						skuCategoryPriceMap[catItem] += item.price * item.num;
						//skuCategoryPriceMap[catItem] += that.isVip ? (item.vipPrice * item.num) : (item.price * item.num)
					} else {
						skuCategoryPriceMap[catItem] += item.price * item.num;
						//skuCategoryPriceMap[catItem] = that.isVip ? (item.vipPrice) : (item.price)
					}
				});
			});
			that.skuCategoryPriceMap = skuCategoryPriceMap;
			that.orderReqeust.totalOriginalPrice = totalOriginalPrice;
			that.orderReqeust.totalNumber = totalNumber;
			that.orderReqeust.totalPrice = totalPrice;
			// that.$api.request('coupon', 'getUserCoupons').then(res => {
			// 	that.couponList = res.data
			// })

			that.$api.request('address', 'getDefAddress').then(res => {
				if (res.data) {
					that.addressData = res.data;
				}
				that.calcFreightPrice();
			});

			if (that.orderReqeust.skuList.length === 1 && that.orderReqeust.skuList[0].groupShopId) {
				//若是团购商品，则携带上团购信息
				that.orderReqeust.groupShopId = that.orderReqeust.skuList[0].groupShopId;
			}
			this.calcTime();
		},
		methods: {
			// 优惠卷后的团购价格
			youhuizhe() {
				let c =
					Math.floor(
						((this.orderReqeust.totalPrice - (this.orderReqeust.coupon ? this.orderReqeust.coupon.discount : 0) + this.orderReqeust
							.freightPrice) / 100.0) *
						(1 - (this.maxUserCount * this.eachDiscount) / 100) *
						100
					) / 100;
				this.mey = c;
				// console.log(+this.huiItem,8910);
				if (this.youhui == '已选一张') {
					if (c >= this.huiItem.couponDO.min) {
						return (
							Math.floor(
								((this.orderReqeust.totalPrice - (this.orderReqeust.coupon ? this.orderReqeust.coupon.discount : 0) + this.orderReqeust
										.freightPrice) / 100.0 -
									this.huiItem.couponDO.discount) *
								(1 - (this.maxUserCount * this.eachDiscount) / 100) *
								100
							) / 100
						);
					} else {
						return c;
					}
				} else {
					return c;
				}
			},
			// 优惠卷后的价格
			dandu() {
				let c = Math.floor(((this.orderReqeust.totalPrice - (this.orderReqeust.coupon ? this.orderReqeust.coupon.discount :
					0) + this.orderReqeust.freightPrice) / 100.0) * 100) / 100;
				if (this.youhui == '已选一张') {
					return c - +this.huiItem.couponDO.discount;
				} else {
					return c;
				}
			},
			GoYouhui() {
				let c = (this.orderReqeust.totalPrice - (this.orderReqeust.coupon ? this.orderReqeust.coupon.discount : 0) + this.orderReqeust
					.freightPrice) / 100.0;
				uni.navigateTo({
					url: `/pagesA/PanicBuying/PanicBuying?type=${c}`
				});
			},
			showZhe() {
				this.$api.request('admin.help', 'getAppHelpConfig', {}).then(res => {
					uni.hideLoading();
					// console.log(res,11111);
					this.maxUserCount = res.data.maxUserCount;
					this.eachDiscount = res.data.eachDiscount;
				});
			},
			Pinsubmit() {
				let that = this;
				this.$api.request('order', 'userHaveHelpOrder', {}).then(res => {
					uni.hideLoading();
					// console.log(res);
					if (res.data != 0) {
						// console.log(res.data);
						let oderNo = res.data;
						// return
						uni.showModal({
							title: '提示',
							content: '你已经有一个订单是否放弃？',
							success: function(res) {
								if (res.confirm) {
									that.$api
										.request('order', 'cancel', {
											orderNo: oderNo
										})
										.then(res => {
											uni.hideLoading();
											console.log(res);
											uni.showToast({
												title: '您已成功放弃订单',
												icon: 'none'
											});
										});
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
					} else {
						if (!that.shifouchaochu) {
							that.$api.msg('超出配送范围!');
							return;
						}
						// console.log(this.orderReqeust);
						console.log('点击', that.addressData);

						let Pintuan = uni.getStorageSync('faPintuan');
						// 拼团订单
						if (Pintuan.length > 0) {
							// console.log(123);
							const that = that;
							if (that.submiting) {
								return;
							}
							if (!that.addressData.id) {
								that.$api.msg('请选择配送地址');
								return;
							}
							uni.showLoading({});
							that.submiting = true;
							if (that.addressData.id) {
								that.orderReqeust.addressId = that.addressData.id;
							}
							that.orderReqeust.storageId = that.$store.state.storageId;

							that.orderReqeust.groupShopId = Pintuan[0].groupShopId;
							that.orderReqeust.createId = Pintuan[0].createId;
							that.orderReqeust.groupShopNo = Pintuan[0].groupShopNo;
							// console.log(that.orderReqeust);

							that.orderReqeust.userCouponId = this.huiItem.id;
							// return
							that.$api
								.request(
									'order',
									'takeOrder', {
										orderRequest: JSON.stringify(that.orderReqeust),
										channel: uni.getSystemInfoSync().platform
									},
									failres => {
										that.submiting = false;
										that.$api.msg(failres.errmsg);
									}
								)
								.then(res => {
									//提交订单成功后，无需再让用户提交订单
									that.submiting = false;
									uni.redirectTo({
										url: '/pages/pay/pay?orderno=' + res.data + '&price=' + that.orderReqeust.totalPrice
									});
									//that.confirm(res.data)
								});
							return;
						}

						// console.log(456);
						// return

						if (that.submiting) {
							return;
						}
						if (!that.addressData.id) {
							that.$api.msg('请选择配送地址');
							return;
						}
						uni.showLoading({});
						that.submiting = true;
						if (that.addressData.id) {
							that.orderReqeust.addressId = that.addressData.id;
						}
						that.orderReqeust.storageId = that.$store.state.storageId;
						that.orderReqeust.isHelpOrder = 1;
						if (that.youhui == '已选一张' && that.mey >= that.huiItem.couponDO.min) {
							that.orderReqeust.userCouponId = that.huiItem.id;

						} else if (that.youhui == '已选一张') {
							uni.showToast({
								title: '当前优惠卷不满足使用条件',
								icon: 'none'
							})
							return
						}

						// console.log(that.orderReqeust,1212);
						// return
						that.$api
							.request(
								'order',
								'takeOrder', {
									orderRequest: JSON.stringify(that.orderReqeust),
									channel: uni.getSystemInfoSync().platform
								},
								failres => {
									that.submiting = false;
									that.$api.msg(failres.errmsg);
								}
							)
							.then(res => {
								//提交订单成功后，无需再让用户提交订单
								uni.hideLoading();
								that.submiting = false;
								uni.setStorageSync('oderNo', res.data);
								uni.navigateTo({
									url: 'share'
								});
								// uni.redirectTo({
								// 	url: '/pages/pay/pay?orderno=' + res.data + '&price=' + that.orderReqeust.totalPrice
								// });
								//that.confirm(res.data)
							});
					}
				});
			},
			//显示优惠券面板
			toggleMask(type) {
				let timer = type === 'show' ? 10 : 300;
				let state = type === 'show' ? 1 : 0;
				this.maskState = 2;
				setTimeout(() => {
					this.maskState = state;
				}, timer);
			},
			calcFreightPrice() {
				const that = this;
				if (that.addressData) {
					console.log('that.addressData', that.addressData);
					that.getjingwei(); //获取经纬度
					that.orderReqeust.addressId = that.addressData.id;
				}
				that.$api
					.request('freight', 'getFreightMoney', {
						orderRequestDTO: JSON.stringify(that.orderReqeust)
					})
					.then(res => {
						that.orderReqeust.freightPrice = res.data;
					});
			},
			numberChange(data) {
				this.number = data.number;
			},
			//获取经纬度
			getjingwei() {
				let that = this;
				let addr = this.addressData.province + this.addressData.city + this.addressData.address;
				if (!addr) {
					return;
				}
				that.$api
					.request('user', 'getLgLatByAddress', {
						address: addr
					})
					.then(res => {
						that.$api
							.request('user', 'compareAddress', {
								lg: res.data.result.location.lng,
								lat: res.data.result.location.lat,
								storageId: that.$store.state.storageId
							})
							.then(res => {
								// that.$api.msg('对比成功');
								that.shifouchaochu = res.data;
								console.log('地址是否匹配', res);
							});
					});
			},
			submitTwo() {},
			submit() {
				if (!this.shifouchaochu) {
					this.$api.msg('超出配送范围!');
					return;
				}
				// console.log(this.orderReqeust);
				console.log('点击', this.addressData);

				let Pintuan = uni.getStorageSync('faPintuan');
				// 拼团订单
				if (Pintuan.length > 0) {
					// console.log(123);
					const that = this;
					if (that.submiting) {
						return;
					}
					if (!this.addressData.id) {
						this.$api.msg('请选择配送地址');
						return;
					}
					uni.showLoading({});
					that.submiting = true;
					if (that.addressData.id) {
						that.orderReqeust.addressId = that.addressData.id;
					}
					that.orderReqeust.storageId = that.$store.state.storageId;

					that.orderReqeust.groupShopId = Pintuan[0].groupShopId;
					that.orderReqeust.createId = Pintuan[0].createId;
					that.orderReqeust.groupShopNo = Pintuan[0].groupShopNo;
					// console.log(that.orderReqeust);
					// return
					that.orderReqeust.userCouponId = this.huiItem.id;
					that.$api
						.request(
							'order',
							'takeOrder', {
								orderRequest: JSON.stringify(that.orderReqeust),
								channel: uni.getSystemInfoSync().platform
							},
							failres => {
								that.submiting = false;
								that.$api.msg(failres.errmsg);
							}
						)
						.then(res => {
							//提交订单成功后，无需再让用户提交订单
							that.submiting = false;

							uni.redirectTo({
								url: '/pages/pay/pay?orderno=' + res.data + '&price=' + that.orderReqeust.totalPrice
							});
							//that.confirm(res.data)
						});
					return;
				}

				// console.log(456);
				// return
				const that = this;
				if (that.submiting) {
					return;
				}
				if (!this.addressData.id) {
					this.$api.msg('请选择配送地址');
					return;
				}
				uni.showLoading({});
				that.submiting = true;
				if (that.addressData.id) {
					that.orderReqeust.addressId = that.addressData.id;
				}
				that.orderReqeust.storageId = that.$store.state.storageId;
				// console.log(that.orderReqeust,1212);
				// return
				that.orderReqeust.userCouponId = this.huiItem.id;

				// userCouponId: this.huiItem.id
				that.$api
					.request(
						'order',
						'takeOrder', {
							orderRequest: JSON.stringify(that.orderReqeust),
							channel: uni.getSystemInfoSync().platform
						},
						failres => {
							that.submiting = false;
							that.$api.msg(failres.errmsg);
						}
					)
					.then(res => {
						//提交订单成功后，无需再让用户提交订单
						that.submiting = false;

						uni.redirectTo({
							url: '/pages/pay/pay?orderno=' + res.data + '&price=' + that.orderReqeust.totalPrice
						});
						//that.confirm(res.data)
					});
			},
			selectCoupon(couponItem) {
				this.orderReqeust.coupon = couponItem;
				this.maskState = 0;
				this.calcFreightPrice();
			},
			stopPrevent() {},
			//打开选择时间的弹窗
			selectTime() {
				this.$refs.popup.open();
			},
			//根据当前仓库营业时段及当前时间计算可供选择的送达时间
			calcTime() {
				// console.log(544545);
				var deliveryStart = this.$store.state.storageObj.deliveryStartTime.split(':');
				var deliveryStop = this.$store.state.storageObj.deliveryStopTime.split(':');
				var startHour = parseInt(deliveryStart[0]);
				var startMin = parseInt(deliveryStart[1]);
				var stopHour = parseInt(deliveryStop[0]);
				var stopMin = parseInt(deliveryStop[1]);
				var date = new Date();
				var month = date.getMonth() + 1 > 9 ? date.getMonth() + 1 : '0' + parseInt(date.getMonth() + 1);
				var day = date.getDate() > 9 ? date.getDate() : '0' + date.getDate();
				var tomorrow = date.getDate() + 1 > 9 ? date.getDate() + 1 : '0' + parseInt(date.getDate() + 1);
				var afterTomo = date.getDate() + 2 > 9 ? date.getDate() + 2 : '0' + parseInt(date.getDate() + 2);

				this.dateObj.today = day;
				this.dateObj.tomorrow = tomorrow;
				this.dateObj.afterTomo = afterTomo;
				this.dateObj.month = month;

				this.dayList[0] = '今天' + month + '月' + day + '日';
				this.dayList[1] = '明天' + month + '月' + tomorrow + '日';
				this.dayList[2] = '后天' + month + '月' + afterTomo + '日';
				(this.timeList[0] = ['尽快送达']), (this.timeList[1] = []);
				for (var i = 0; i < stopHour - startHour; i++) {
					var time = startHour + i > 9 ? parseInt(startHour + i) : '0' + parseInt(startHour + i);
					this.timeList[1].push([time + ':00', time + ':30']);
					this.timeList[1].push([time + ':30', parseInt(parseInt(time) + 1) + ':00']);
				}
				if (startMin >= 30) {
					//半点后配送，删除第一条记录
					this.timeList[1].splice(0, 1);
				}
				//预计送达时间字符
				this.orderReqeust.predictTime = this.dayList[1] + this.timeList[1][0][0] + '-' + this.timeList[1][0][1];
				this.orderReqeust.gmtPredict = new Date(this.year + this.dateObj.month + '-' + this.dateObj.tomorrow + ' ' + this.timeList[
					1][0][1]).getTime();
				this.timeList[2] = [];
				for (var i = 0; i < stopHour - startHour; i++) {
					var time = startHour + i > 9 ? parseInt(startHour + i) : '0' + parseInt(startHour + i);
					this.timeList[2].push([time + ':00', time + ':30']);
					this.timeList[2].push([time + ':30', parseInt(parseInt(time) + 1) + ':00']);
				}
				if (startMin >= 30) {
					//半点后配送，删除第一条记录
					this.timeList[2].splice(0, 1);
				}
				var now = date.getHours();
				if (now < startHour) {
					now = startHour;
				}
				var nowTime = date.getMinutes();
				this.nowTime = nowTime;
				this.now = now;
				if (now >= stopHour) {
					this.dayList.splice(0, 1);
					this.timeList.splice(0, 1);
				} else {
					this.timeList[0] = ['尽快送达'];
					for (var i = 0; i < stopHour - now; i++) {
						var time = now + i > 9 ? now + i : '0' + parseInt(now + i);
						this.timeList[0].push([time + ':00', time + ':30']);
						this.timeList[0].push([time + ':30', parseInt(now + i + 1) + ':00']);
					}
					if (nowTime > 30) {
						this.timeList[0].splice(1, 2);
						var timeMine = nowTime - 30 > 9 ? parseInt(nowTime - 30) : '0' + parseInt(nowTime - 30);
						this.orderReqeust.predictTime = '尽快送达（预计' + parseInt(now + 1) + ':' + timeMine + '送达)';
						this.orderReqeust.gmtPredict = new Date(this.year + this.dateObj.month + '-' + this.dateObj.today + ' ' +
							parseInt(now + 1) + ':' + timeMine).getTime();
					} else if (nowTime < 29) {
						this.orderReqeust.predictTime = '尽快送达（预计' + now + ':' + parseInt(nowTime + 30) + '送达)';
						this.orderReqeust.gmtPredict = new Date(this.year + this.dateObj.month + '-' + this.dateObj.today + ' ' + now +
							':' + parseInt(nowTime + 30)).getTime();
					} else if (nowTime == 30) {
						this.timeList[0].splice(1, 1);
						this.orderReqeust.predictTime = '尽快送达（预计' + parseInt(now + 1) + ':00送达)';
						this.orderReqeust.gmtPredict = new Date(this.year + this.dateObj.month + '-' + this.dateObj.today + ' ' +
							parseInt(now + 1) + ':00').getTime();
					}
				}
			},
			chooseDay(index) {
				this.dayIndex = index;
			},
			chooseTime(index) {
				this.timeIndex = index;
			},
			checkTime() {
				//当天尽快送达
				if (this.dayIndex == 0 && this.timeIndex == 0 && this.dayList.length >= 3) {
					if (this.nowTime > 30) {
						var timeMine = this.nowTime - 30 > 9 ? parseInt(this.nowTime - 30) : '0' + parseInt(this.nowTime - 30);
						this.orderReqeust.predictTime = '尽快送达（预计' + parseInt(this.now + 1) + ':' + timeMine + '送达)';
						this.orderReqeust.gmtPredict = new Date(this.year + this.dateObj.month + '-' + this.dateObj.today + ' ' +
							parseInt(this.now + 1) + ':' + timeMine).getTime();
					} else if (this.nowTime < 29) {
						this.orderReqeust.predictTime = '尽快送达（预计' + this.now + ':' + parseInt(this.nowTime + 30) + '送达)';
						this.orderReqeust.gmtPredict = new Date(
							this.year + this.dateObj.month + '-' + this.dateObj.today + ' ' + this.now + ':' + parseInt(this.nowTime + 30)
						).getTime();
					} else if (this.nowTime == 30) {
						this.orderReqeust.predictTime = '尽快送达（预计' + parseInt(this.now + 1) + ':00送达)';
						this.orderReqeust.gmtPredict = new Date(this.year + this.dateObj.month + '-' + this.dateObj.today + ' ' +
							parseInt(this.now + 1) + ':00').getTime();
					}
					this.$refs.popup.close();
					console.log(this.orderReqeust);
					return;
				}
				//当天送达
				if (this.dayIndex == 0 && this.dayList.length >= 3) {
					this.orderReqeust.predictTime = this.timeList[0][this.timeIndex][0] + '-' + this.timeList[0][this.timeIndex][1];
					console.log(this.year + this.dateObj.month + '-' + this.dateObj.today + ' ' + this.timeList[this.dayIndex][this.timeIndex]
						[1]);
					this.orderReqeust.gmtPredict = new Date(
						this.year + this.dateObj.month + '-' + this.dateObj.today + ' ' + this.timeList[this.dayIndex][this.timeIndex][1]
					).getTime();
					this.$refs.popup.close();
					console.log(this.orderReqeust);
					return;
				}
				//明、后天送达
				this.orderReqeust.predictTime = this.dayList[this.dayIndex] + this.timeList[this.dayIndex][this.timeIndex][0] + '-' +
					this.timeList[this.dayIndex][this.timeIndex][1];
				if (this.dayList.length >= 3) {
					if (this.dayIndex == 1) {
						//明天
						this.orderReqeust.gmtPredict = new Date(
							this.year + this.dateObj.month + '-' + this.dateObj.tomorrow + ' ' + this.timeList[this.dayIndex][this.timeIndex]
							[1]
						).getTime();
					} else if (this.dayIndex == 2) {
						//后天
						this.orderReqeust.gmtPredict = new Date(
							this.year + this.dateObj.month + '-' + this.dateObj.afterTomo + ' ' + this.timeList[this.dayIndex][this.timeIndex]
							[1]
						).getTime();
					}
				} else if (this.dayList.length >= 2) {
					if (this.dayIndex == 0) {
						//明天
						this.orderReqeust.gmtPredict = new Date(
							this.year + this.dateObj.month + '-' + this.dateObj.tomorrow + ' ' + this.timeList[this.dayIndex][this.timeIndex]
							[1]
						).getTime();
					} else if (this.dayIndex == 1) {
						//后天
						this.orderReqeust.gmtPredict = new Date(
							this.year + this.dateObj.month + '-' + this.dateObj.afterTomo + ' ' + this.timeList[this.dayIndex][this.timeIndex]
							[1]
						).getTime();
					}
				}
				this.$refs.popup.close();
				console.log(this.orderReqeust);
			},
			//确认支付
			confirm(orderNo) {
				const that = this;
				that.$api
					.request(
						'order',
						'wxPrepay', {
							orderNo: orderNo
						},
						failres => {
							that.submiting = false;
							that.$api.msg(failres.errmsg);
						}
					)
					.then(prepayRes => {
						uni.hideLoading();
						that.submiting = false;
						//#ifdef MP-WEIXIN
						const payParam = {
							appId: prepayRes.data.appId,
							nonceStr: prepayRes.data.nonceStr,
							package: prepayRes.data.packageValue,
							timeStamp: prepayRes.data.timeStamp,
							signType: prepayRes.data.signType,
							paySign: prepayRes.data.paySign
						};
						//#endif
						//#ifdef APP-PLUS
						const payParam = {
							appid: prepayRes.data.appId,
							noncestr: prepayRes.data.nonceStr,
							package: prepayRes.data.packageValue,
							partnerid: prepayRes.data.partnerId,
							prepayid: prepayRes.data.prepayId,
							timestamp: parseInt(prepayRes.data.timeStamp),
							sign: prepayRes.data.sign,
							signType: 'MD5'
						};
						//#endif
						//#ifdef MP-WEIXIN || APP-PLUS
						uni.requestPayment({
							provider: 'wxpay',
							//#ifdef MP-WEIXIN
							...payParam,
							//#endif
							//#ifdef APP-PLUS
							orderInfo: payParam,
							//#endif
							success: function(res) {
								uni.redirectTo({
									url: '/pages/pay/success'
								});
							},
							fail: function(res) {
								// console.log("支付过程失败");
								// that.$api.msg(JSON.stringify(res))
							},
							complete: function(res) {
								console.log('支付过程结束');
							}
						});
						//#endif
						//#ifdef H5
						that.$jweixin.chooseWXPay({
							nonceStr: prepayRes.data.nonceStr,
							timestamp: prepayRes.data.timeStamp,
							package: prepayRes.data.packageValue,
							signType: prepayRes.data.signType,
							paySign: prepayRes.data.paySign,
							success: e => {
								//支付成功
								uni.redirectTo({
									url: '/pages/pay/success'
								});
							},
							fail: function(res) {
								console.log('支付过程失败');
								that.$api.msg(JSON.stringify(res));
							},
							complete: function(res) {
								console.log('支付过程结束');
							}
						});
						//#endif
					});
			}
		}
	};
</script>

<style lang="scss">
	page {
		background: #f4f4f4;
		padding-bottom: 100upx;
	}

	.address {
		padding: 36upx 30upx;
		background-color: #ffffff;
		overflow: hidden;
	}

	.address-head {
		color: #999999;
		font-size: 28upx;
		font-weight: 400;
	}

	.address-main {
		margin-top: 24upx;
	}

	.address-left {
		margin: 9upx 0;
		width: 24upx;
		height: 32upx;
		float: left;
	}

	.address-text {
		margin-left: 14upx;
		float: left;
		font-size: 36upx;
		color: #333333;
		font-weight: 500;
	}

	.address-right {
		margin: 11upx 20upx 11upx 0;
		width: 28upx;
		height: 28upx;
		float: right;
	}

	.address-distance {
		clear: both;
		margin-top: 10upx;
		color: #333333;
		font-size: 30upx;
	}

	.a-bg {
		display: block;
		width: 100%;
		height: 5upx;
	}

	.goods {
		margin-top: 20upx;
		background-color: #ffffff;
		overflow: hidden;
	}

	.goods-head {
		margin: 0 30upx;
		height: 100upx;
		padding: 30upx 0;
		border-bottom: 2upx solid #f1f1f1;
	}

	.goods-head-text {
		width: 294upx;
		float: left;
		color: #333333;
		font-size: 28upx;
	}

	.goods-head-time {
		width: 490upx;
		float: left;
		color: #2aac34;
		font-size: 28upx;
	}

	.goods-head-right {
		margin-top: 8upx;
		width: 16upx;
		height: 24upx;
		float: left;
	}

	.goods-one {
		padding: 40upx 0 30upx 0;
		margin: 0 30upx;
		height: 190upx;
	}

	.scroll_box {
		width: 544upx;
		height: 110upx;
		float: left;
		overflow: hidden;
	}

	.scroll_box scroll-view {
		height: 110upx;
		width: 544upx;
		white-space: nowrap;
	}

	.goods-img {
		margin-top: 2upx;
		width: 118upx;
		height: 110upx;
		float: left;
	}

	.goods-more-img {
		margin-top: 2upx;
		width: 118upx;
		height: 110upx;
		display: inline-block;
		margin-right: 36upx;
	}

	.goods-more-number {
		width: 126upx;
		height: 110upx;
		line-height: 110upx;
		text-align: center;
		color: #1b1c33;
		font-size: 28upx;
		float: left;
	}

	.goods-more-right {
		margin-top: 43.5upx;
		width: 15upx;
		height: 23upx;
		float: left;
	}

	.goods-text {
		margin-top: 6upx;
		margin-left: 32upx;
		width: 538upx;
		height: 110upx;
		float: left;
	}

	.goods-name {
		width: 500upx;
		line-height: 44upx;
		overflow: hidden;
		color: #333333;
		font-size: 32upx;
	}

	.goods-tag {
		margin-top: 10upx;
	}

	.goods-price {
		float: left;
		color: #333333;
		font-size: 32upx;
		line-height: 44upx;
	}

	.goods-yprice {
		margin-left: 16upx;
		float: left;
		color: #aeaeae;
		font-size: 24upx;
		line-height: 44upx;
		text-decoration: line-through;
	}

	.goods-number {
		float: right;
		color: #333333;
		font-size: 32upx;
	}

	.distribution {
		padding: 0 30upx;
		margin-top: 20upx;
		background-color: #ffffff;
		overflow: hidden;
	}

	.distribution-list {
		height: 100upx;
		line-height: 100upx;
		font-size: 28upx;
		clear: both;
	}

	.distribution-list-bottom {
		border-bottom: 2upx solid #f1f1f1;
	}

	.distribution-text {
		width: 200upx;
		float: left;
		color: #333333;
	}

	.distribution-price {
		width: 490upx;
		float: left;
		text-align: right;
		color: #666666;
	}

	.distribution-price input {
		width: 490upx;
		height: 100upx;
		line-height: 100upx;
		overflow: hidden;
		text-align: right;
	}

	.pay-text {
		color: #333333;
		font-size: 32upx;
	}

	.distribution-price image {
		width: 40upx;
		height: 40upx;
		float: right;
		margin-top: 30upx;
	}

	.footer {
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 99;
		height: 98upx;
		width: 100%;
		// background-color: #ffffff;
		background-color: #2aac34;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.price {
		margin-left: 62upx;
		width: 448upx;
		float: left;
	}

	.price-content {
		height: 50upx;
		line-height: 50upx;
		margin-top: 10upx;
		color: #666666;
		font-size: 26upx;
	}

	.price-content-money {
		color: #2aac34;
		font-size: 36upx;
	}

	.price-preferential {
		height: 36upx;
		line-height: 36upx;
		color: #aeaeae;
		font-size: 20upx;
	}

	.submit {
		/* width: 240upx; */
		width: 50%;
		height: 120rpx;
		float: left;
		// line-height: 98upx;
		color: #ffffff;

		text-align: center;

		text {
			font-size: 24rpx;
		}

		background-color: #2aac34;
	}

	.submitTwo {
		/* width: 240upx; */
		width: 50%;
		height: 120rpx;
		float: left;
		// line-height: 98upx;
		color: #ffffff;
		background-color: #41bb4d;
		text-align: center;

		text {
			font-size: 24rpx;
		}
	}
</style>
